{  Statement: http://acmp.ru/?main=task&id_task=114
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i, n, k, tt : longint;
    a, b, t : int64;
    
begin
    reset(input,'input.txt');
    rewrite(output,'output.txt');
    read(n, k);
    a := k - 1;
    b := 1;
    tt := k - 1;
    for i := 2 to n do begin
        t := a;
        a := (a + b) * tt;
        b := t;
    end;
    write(a);
end.